package com.lee.boot.batch.step;

import com.lee.boot.batch.model.ProductDO;
import org.springframework.batch.core.ItemProcessListener;
import org.springframework.batch.core.ItemWriteListener;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.StepListener;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.core.step.builder.StepBuilder;
import org.springframework.batch.item.ItemWriter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author: Lee
 * @Date: 2019/12/25 0025 23:31
 * @Description:
 */
@Component("fileWriter")
public class FileWriter implements ItemWriter<ProductDO>, ItemWriteListener {



    @Override
    public void write(List<? extends ProductDO> items) throws Exception {
        System.out.println("write");
    }


    /**
     * Called before {@link ItemWriter#write(List)}
     *
     * @param items to be written
     */
    @Override
    public void beforeWrite(List items) {

    }

    /**
     * Called after {@link ItemWriter#write(List)} This will be
     * called before any transaction is committed, and before
     *
     *
     * @param items written items
     */
    @Override
    public void afterWrite(List items) {

    }

    /**
     * Called if an error occurs while trying to write. Will be called inside a
     * transaction, but the transaction will normally be rolled back. There is
     * no way to identify from this callback which of the items (if any) caused
     * the error.
     *
     * @param exception thrown from {@link ItemWriter}
     * @param items     attempted to be written.
     */
    @Override
    public void onWriteError(Exception exception, List items) {

    }
}
